import request from '@/axios'
import {
  MenuAllResponse,
  MenuCreateData,
  MenuPageParams,
  MenuUpdateData,
  PermissionType
} from '@/api/menu/types'

export const getMenuListApi = (): Promise<IResponse<MenuAllResponse[]>> => {
  return request.get({ url: '/menus/list' })
}

export const getAllMenuTreeApi = (): Promise<IResponse<MenuAllResponse[]>> => {
  return request.get({ url: '/menus/list/all' })
}

export const getMenuPageApi = (params: MenuPageParams): Promise<IResponse<MenuAllResponse[]>> => {
  return request.get({ url: '/menus/page', params })
}

export const getMenuPermsCodeApi = (): Promise<IResponse<PermissionType>> => {
  return request.get({ url: '/menus/perms/all' })
}

export const deleteMenuApi = (id: number): Promise<IResponse> => {
  return request.delete({ url: `/menus/delete/${id}` })
}

export const createMenuApi = (data: MenuCreateData): Promise<IResponse> => {
  return request.post({ url: '/menus/create', data })
}

export const updateMenuApi = (data: MenuUpdateData): Promise<IResponse> => {
  return request.put({ url: `/menus/update/${data.id}`, data })
}
